-
Notifications
You must be signed in to change notification settings - Fork 580
feat(integration): add gen_ai.conversation.id if available
#5307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(integration): add gen_ai.conversation.id if available
#5307
Conversation
…_ai.conversation.id`
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Span Streaming
Other
Bug Fixes 🐛Span Streaming
Other
Internal Changes 🔧Fastmcp
Mcp
Other
🤖 This preview updates automatically when you update the PR. |
…nts-conversation-id
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 8.49s All tests are passing successfully. ❌ Patch coverage is 8.33%. Project has 13741 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| # Set conversation ID on workflow span early so it's captured even on errors | ||
| conversation_id = kwargs.get("conversation_id") | ||
| if conversation_id: | ||
| agent._sentry_conversation_id = conversation_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing conversation_id on workflow span in async runner
Medium Severity
In _create_run_wrapper, the comment says "Set conversation ID on workflow span early" but the code only stores conversation_id on the agent object (agent._sentry_conversation_id). Unlike the streaming version _create_run_streamed_wrapper, there's no call to set_data(SPANDATA.GEN_AI_CONVERSATION_ID, conversation_id) on the workflow span itself. The workflow span (transaction) will be missing the gen_ai.conversation.id field when using Runner.run().
| if agent: | ||
| conv_id = getattr(agent, "_sentry_conversation_id", None) | ||
| if conv_id: | ||
| span.set_data(SPANDATA.GEN_AI_CONVERSATION_ID, conv_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Callers don't pass agent to update_ai_client_span
Medium Severity
The update_ai_client_span function was modified to accept a new agent parameter (defaulting to None) for setting conversation_id on AI client spans. However, the callers in models.py at lines 128 and 179 were not updated to pass the agent argument. Since agent defaults to None, the conversation_id condition if agent: is never true, and gen_ai.conversation.id is never set on AI client spans.
| # Add conversation ID from agent | ||
| conv_id = getattr(agent, "_sentry_conversation_id", None) | ||
| if conv_id: | ||
| span.set_data(SPANDATA.GEN_AI_CONVERSATION_ID, conv_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated pattern for setting conversation ID on spans
Low Severity
The same 3-line pattern for extracting and setting _sentry_conversation_id from an agent onto a span is repeated 4 times across execute_tool.py, handoff.py, invoke_agent.py, and ai_client.py. This pattern should be extracted to a utility function in utils.py (e.g., _set_conversation_id(span, agent)), following the existing pattern of _set_agent_data, _set_usage_data, etc.


Description
Closes https://linear.app/getsentry/issue/TET-1721/openai-agents-add-gen-aiconversationid